package com.ljf.framework.result;

import java.io.Serializable;

/**
 * @Auther: lijinfeng
 * @Date: 2022/4/23
 * @Description 描述: 封装JSON格式的通用返回对象
 */
public class JsonResult implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 数据对象
     */
    private Object data;

    /**
     * 响应状态
     */
    private Integer status;

    /**
     * 响应信息
     */
    private String message;



    private JsonResult(JsonResultEnum resultEnum, Object data) {
        this.status = resultEnum.getCode();
        this.message = resultEnum.getMessage();
        this.data = data;
    }

    private JsonResult(JsonResultEnum resultEnum, String message, Object data) {
        this.status = resultEnum.getCode();;
        this.message = message;
        this.data = data;
    }




    public static JsonResult success() {
        return new JsonResult(JsonResultEnum.SUCCESS, null);
    }

    public static JsonResult success(Object data) {
        return new JsonResult(JsonResultEnum.SUCCESS, data);
    }


    public static JsonResult success(JsonResultEnum resultEnum) {
        return new JsonResult(resultEnum, null);
    }

    public static JsonResult success(JsonResultEnum resultEnum, Object data) {
        return new JsonResult(resultEnum, data);
    }

    public static JsonResult success(JsonResultEnum resultEnum, String message, Object data) {
        return new JsonResult(resultEnum, message, data);
    }


    public static JsonResult error() {
        return new JsonResult(JsonResultEnum.ERROR, null);
    }

    public static JsonResult error(Object data) {
        return new JsonResult(JsonResultEnum.ERROR, data);
    }

    public static JsonResult error(JsonResultEnum resultEnum) {
        return new JsonResult(resultEnum, null);
    }

    public static JsonResult error(JsonResultEnum resultEnum, Object data) {
        return new JsonResult(resultEnum, data);
    }

    public static JsonResult error(JsonResultEnum resultEnum, String message, Object data) {
        return new JsonResult(resultEnum, message, data);
    }


    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    private JsonResult() {
    }

}

